package com.zrrd.mybatis_02.mapper;

import com.zrrd.mybatis_02.entity.Student;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author WanJl
 * @version 1.0
 * @title StudentMapper
 * @description
 * @create 2024/10/17
 */
public interface StudentMapper {
    /**
     * 根据班级id查询学生列表
     * @param cid
     * @return
     */
    @Select("SELECT * FROM student WHERE cid=#{cid}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "name",property = "studentName"),
            @Result(column = "age",property = "studentAge")
    })
    List<Student> selectByCid(int cid);

    /**
     * 查询全部已选课的学生列表
     * @return
     */
    @Select("SELECT DISTINCT s.id stu_id,s.name stu_name,s.age stu_age FROM student s LEFT JOIN stu_cr sc " +
            "ON sc.sid=s.id")
    @Results({
            @Result(column = "stu_id",property ="id" ),
            @Result(column = "stu_name",property ="studentName" ),
            @Result(column = "stu_age",property ="studentAge" ),
            @Result(column = "stu_id",
                    javaType = List.class,
                    property = "courseList",
                    many = @Many(select = "com.zrrd.mybatis_02.mapper.CourseMapper.selectCourseByStudentId")
            )
    })
    List<Student> selectCourseStudent();
}
